let path = getDataPath();
// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
    // loadFnc();
});
// 获取时间
var showtime = function () {

    var nowdate = new Date();

    var year = nowdate.getFullYear(),

        month = nowdate.getMonth() + 1,

        date = nowdate.getDate()
    return year + "年" + month + "月" + date + "日";
}
setTimeout(() => {
    document.getElementById('sp_Sdate').innerHTML = '最新状态 (' + showtime() + ')'
}, 1000);
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        loadFnc();
    }
    else OpenErrmsg("web/errhtml/404.html");
}
function loadFnc() {
    InitIMGData();
    // InitTimeData();
    InitStatusData();
    // getNowTime()
}
// 加载图片数据
function InitIMGData() {
    let data = {
        "Group1_LL_F": "0",
        "Group1_LH_F": "0",
        "Group1_LL_Site": "0",
        "Group1_LH_Site": "0",
        "Group1_Compressor_Inlet_T_high": "0", // 一级压缩机入口温度
        "Group1_Compressor_A_Outlet_T_high": "0",
        "Group1_Compressor_A_Outlet_P_low": "0",
        "Group1_Compressor_A_Outlet_P_high": "0",
        "Group1_Compressor_B_Outlet_T_high": "0",
        "Group1_Compressor_B_Outlet_P_low": "0",
        "Group1_Compressor_B_Outlet_P_high": "0",
        "Group1_Aftercooler_Outlet_T_low": "0",
        "Group1_Aftercooler_Outlet_T_high": "0",
        // 二级压缩机
        "Group2_LL_F": "0",
        "Group2_LH_F": "0",
        "Group2_LL_Site": "0",
        "Group2_LH_Site": "0",
        "Group2_Compressor_Inlet_T_high": "0", // 二级压缩机入口温度
        "Group2_Compressor_A_Outlet_T_high": "0",
        "Group2_Compressor_A_Outlet_P_low": "0",
        "Group2_Compressor_A_Outlet_P_high": "0",
        "Group2_Compressor_B_Outlet_T_high": "0",
        "Group2_Compressor_B_Outlet_P_low": "0",
        "Group2_Compressor_B_Outlet_P_high": "0",
        "Group2_Aftercooler_Outlet_T_low": "0",
        "Group2_Aftercooler_Outlet_T_high": "0",
        // 三级第一压缩机组
        "Group3_LL1_F": "0",
        "Group3_LH1_F": "0",
        "Group3_LL1_Site": "0",
        "Group3_LH1_Site": "0",
        "Group3_Compressor_Inlet_T_high": "0", // 三级压缩机入口温度
        "Group3_Compressor_A_Outlet_T_high": "0",
        "Group3_Compressor_A_Outlet_P_low": "0",
        "Group3_Compressor_A_Outlet_P_high": "0",
        "Group3_Compressor_B_Outlet_T_high": "0",
        "Group3_Compressor_B_Outlet_P_low": "0",
        "Group3_Compressor_B_Outlet_P_high": "0",
        // 三级第二压缩机组
        "Group3_LL2_F": "0",
        "Group3_LH2_F": "0",
        "Group3_LL2_Site": "0",
        "Group3_LH2_Site": "0",
        "Group4_Compressor_Inlet_T_high": "0", // 四级压缩机入口温度
        "Group4_Compressor_A_Outlet_T_high": "0",
        "Group4_Compressor_A_Outlet_P_low": "0",
        "Group4_Compressor_A_Outlet_P_high": "0",
        "Group4_Compressor_B_Outlet_T_high": "0",
        "Group4_Compressor_B_Outlet_P_low": "0",
        "Group4_Compressor_B_Outlet_P_high": "0",
    };
    let dataArr = []
    let url = path + '/ls172/data-analysis/imageStatus'
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        success: function (data) {
            dataArr = data.data.data
        },
        error: function (data) {
            console.log("code", data);
        }
    })
    for (let i = 0; i < dataArr.length; i++) {
        switch (dataArr[i].name) {
            // 一级压缩机
            // 洗涤器
            case "Group1_Scrubber_L_low.PV":
                data.Group1_LL_Site = dataArr[i].vals[3]
                break;
            case "Group1_Scrubber_L_high.PV":
                data.Group1_LH_Site = dataArr[i].vals[3]
                break
            case "Group1_Scrubber_P_low.PV":
                data.Group1_LL_F = dataArr[i].vals[3]
                break;
            case "Group1_Scrubber_P_high.PV":
                data.Group1_LH_F = dataArr[i].vals[3]
                break
            // 压缩机A
            case "Group1_Compressor_Inlet_T_high.PV":
                data.Group1_Compressor_Inlet_T_high = dataArr[i].vals[3]
                break;
            case "Group1_Compressor_A_Outlet_T_high.PV":
                data.Group1_Compressor_A_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group1_Compressor_A_Outlet_P_low.PV":
                data.Group1_Compressor_A_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group1_Compressor_A_Outlet_P_high.PV":
                data.Group1_Compressor_A_Outlet_P_high = dataArr[i].vals[3]
                break
            // 压缩机B
            case "Group1_Compressor_B_Outlet_T_high.PV":
                data.Group1_Compressor_B_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group1_Compressor_B_Outlet_P_low.PV":
                data.Group1_Compressor_B_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group1_Compressor_B_Outlet_P_high.PV":
                data.Group1_Compressor_B_Outlet_P_high = dataArr[i].vals[3]
                break
            // 后冷却器
            case "Group1_Aftercooler_Outlet_T_low.PV":
                data.Group1_Aftercooler_Outlet_T_low = dataArr[i].vals[3]
                break
            case "Group1_Aftercooler_Outlet_T_high.PV":
                data.Group1_Aftercooler_Outlet_T_low = dataArr[i].vals[3]
                break
            // 二级压缩机
            // 洗涤器
            case "Group2_Scrubber_L_low.PV":
                data.Group2_LL_Site = dataArr[i].vals[3]
                break;
            case "Group2_Scrubber_L_high.PV":
                data.Group2_LH_Site = dataArr[i].vals[3]
                break
            case "Group2_Scrubber_P_low.PV":
                data.Group2_LL_F = dataArr[i].vals[3]
                break;
            case "Group2_Scrubber_P_high.PV":
                data.Group2_LH_F = dataArr[i].vals[3]
                break
            // 压缩机A
            case "Group2_Compressor_Inlet_T_high.PV":
                data.Group2_Compressor_Inlet_T_high = dataArr[i].vals[3]
                break;
            case "Group2_Compressor_A_Outlet_T_high.PV":
                data.Group2_Compressor_A_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group2_Compressor_A_Outlet_P_low.PV":
                data.Group2_Compressor_A_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group2_Compressor_A_Outlet_P_high.PV":
                data.Group2_Compressor_A_Outlet_P_high = dataArr[i].vals[3]
                break
            // 压缩机B
            case "Group2_Compressor_B_Outlet_T_high.PV":
                data.Group2_Compressor_B_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group2_Compressor_B_Outlet_P_low.PV":
                data.Group2_Compressor_B_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group2_Compressor_B_Outlet_P_high.PV":
                data.Group2_Compressor_B_Outlet_P_high = dataArr[i].vals[3]
                break
            // 后冷却器
            case "Group2_Aftercooler_Outlet_T_low.PV":
                data.Group2_Aftercooler_Outlet_T_low = dataArr[i].vals[3]
                break
            case "Group2_Aftercooler_Outlet_T_high.PV":
                data.Group2_Aftercooler_Outlet_T_low = dataArr[i].vals[3]
                break
            // 三级第一压缩机
            case "Group3_Scrubber_L_low.PV":
                data.Group3_LL1_Site = dataArr[i].vals[3]
                break;
            case "Group3_Scrubber_L_high.PV":
                data.Group3_LH1_Site = dataArr[i].vals[3]
                break
            case "Group3_Scrubber_P_low.PV":
                data.Group3_LL1_F = dataArr[i].vals[3]
                break;
            case "Group3_Scrubber_P_high.PV":
                data.Group3_LH1_F = dataArr[i].vals[3]
                break
            // 压缩机A
            case "Group3_Compressor_Inlet_T_high.PV":
                data.Group3_Compressor_Inlet_T_high = dataArr[i].vals[3]
                break;
            case "Group3_Compressor_A_Outlet_T_high.PV":
                data.Group3_Compressor_A_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group3_Compressor_A_Outlet_P_low.PV":
                data.Group3_Compressor_A_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group3_Compressor_A_Outlet_P_high.PV":
                data.Group3_Compressor_A_Outlet_P_high = dataArr[i].vals[3]
                break
            // 压缩机B
            case "Group3_Compressor_B_Outlet_T_high.PV":
                data.Group3_Compressor_B_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group3_Compressor_B_Outlet_P_low.PV":
                data.Group3_Compressor_B_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group3_Compressor_B_Outlet_P_high.PV":
                data.Group3_Compressor_B_Outlet_P_high = dataArr[i].vals[3]
                break
            // 三级第二压缩机
            case "Group4_Scrubber_L_low.PV":
                data.Group3_LL2_Site = dataArr[i].vals[3]
                break;
            case "Group4_Scrubber_L_high.PV":
                data.Group3_LH2_Site = dataArr[i].vals[3]
                break
            case "Group4_Scrubber_P_low.PV":
                data.Group3_LL2_F = dataArr[i].vals[3]
                break;
            case "Group4_Scrubber_P_high.PV":
                data.Group3_LH2_F = dataArr[i].vals[3]
                break
            // 压缩机A
            case "Group4_Compressor_Inlet_T_high.PV":
                data.Group4_Compressor_Inlet_T_high = dataArr[i].vals[3]
                break;
            case "Group4_Compressor_A_Outlet_T_high.PV":
                data.Group4_Compressor_A_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group4_Compressor_A_Outlet_P_low.PV":
                data.Group4_Compressor_A_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group4_Compressor_A_Outlet_P_high.PV":
                data.Group4_Compressor_A_Outlet_P_high = dataArr[i].vals[3]
                break
            // 压缩机B
            case "Group4_Compressor_B_Outlet_T_high.PV":
                data.Group4_Compressor_B_Outlet_T_high = dataArr[i].vals[3]
                break
            case "Group4_Compressor_B_Outlet_P_low.PV":
                data.Group4_Compressor_B_Outlet_P_low = dataArr[i].vals[3]
                break;
            case "Group4_Compressor_B_Outlet_P_high.PV":
                data.Group4_Compressor_B_Outlet_P_high = dataArr[i].vals[3]
                break
            default:
                break;
        }
    }
    //一级压缩机组-洗涤器-液位
    $(".imgbackground").append("<div  class=\"" + (data.Group1_LL_Site == "0" && data.Group1_LH_Site == "0" ? "imgclassgreen" : "imgclassred") + "\"  style=\"left:240px;top:125px\"></div>");
    //一级压缩机组-洗涤器-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group1_LL_F == "0" && data.Group1_LH_F == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:250px;top:125px\"></div>");
    //一级压缩机组-压缩机入口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Compressor_Inlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:300px;top:118px\"></div>");
    //一级压缩机组-压缩机A出口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Compressor_A_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:470px;top:117px\"></div>");
    //一级压缩机组-压缩机A出口-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Compressor_A_Outlet_P_low == "0" && data.Group1_Compressor_A_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:490px;top:117px\"></div>");
    //一级压缩机组-压缩机B出口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Compressor_B_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:470px;top:183px\"></div>");
    //一级压缩机组-压缩机B出口-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Compressor_B_Outlet_P_low == "0" && data.Group1_Compressor_B_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:490px;top:183px\"></div>");
    //一级压缩机组-冷却器-2
    $(".imgbackground").append("<div  class=\"" + (data.Group1_Aftercooler_Outlet_T_low == "0" && data.Group1_Aftercooler_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:655px;top:117px\"></div>");


    //二级压缩机组-洗涤器-液位
    $(".imgbackground").append("<div  class=\"" + (data.Group2_LL_Site == "0" && data.Group2_LH_Site == "0" ? "imgclassgreen" : "imgclassred") + "\"  style=\"left:228px;top:288px\"></div>");
    //二级压缩机组-洗涤器-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group2_LL_F == "0" && data.Group2_LH_F == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:238px;top:288px\"></div>");
    //二级压缩机组-压缩机入口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Compressor_Inlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:280px;top:280px\"></div>");
    //二级压缩机组-压缩机A出口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Compressor_A_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:280px\"></div>");
    //二级压缩机组-压缩机A出口-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Compressor_A_Outlet_P_low == "0" && data.Group2_Compressor_A_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:280px\"></div>");
    //二级压缩机组-压缩机B-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Compressor_B_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:368px\"></div>");
    //二级压缩机组-压缩机B出口-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Compressor_B_Outlet_P_low == "0" && data.Group2_Compressor_B_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:368px\"></div>");
    //二级压缩机组-冷却器-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group2_Aftercooler_Outlet_T_low == "0" && data.Group2_Aftercooler_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:655px;top:280px\"></div>");

    //三级第一压缩机组-洗涤器1-液位
    $(".imgbackground").append("<div  class=\"" + (data.Group3_LL1_Site == "0" && data.Group3_LH1_Site == "0" ? "imgclassgreen" : "imgclassred") + "\"  style=\"left:225px;top:505px\"></div>");
    //三级第一压缩机组-洗涤器1-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group3_LL1_F == "0" && data.Group3_LH1_F == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:235px;top:505px\"></div>");
    //三级第一压缩机组-压缩机入口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group3_Compressor_Inlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:175px;top:485px\"></div>");
    //三级第一压缩机组-压缩机A1-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group3_Compressor_A_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:445px\"></div>");
    //三级第一压缩机组-压缩机A1-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group3_Compressor_A_Outlet_P_low == "0" && data.Group3_Compressor_A_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:445px\"></div>");
    //三级第一压缩机组-压缩机B1-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group3_Compressor_B_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:520px\"></div>");
    //三级第一压缩机组-压缩机A1-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group3_DisBotB1_F == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:520px\"></div>");

    //三级第二压缩机组-洗涤器2-液位
    $(".imgbackground").append("<div  class=\"" + (data.Group3_LL2_Site == "0" && data.Group3_LH2_Site == "0" ? "imgclassgreen" : "imgclassred") + "\"  style=\"left:225px;top:665px\"></div>");
    //三级第二压缩机组-洗涤器2-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group3_LL2_F == "0" && data.Group3_LH2_F == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:235px;top:665px\"></div>");
    //三级第二压缩机组-压缩机入口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group4_Compressor_Inlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:175px;top:645px\"></div>");
    //三级第二压缩机组-压缩机A2出口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group4_Compressor_A_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:610px\"></div>");
    //三级第二压缩机组-压缩机A2-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group4_Compressor_A_Outlet_P_low == "0" && data.Group4_Compressor_A_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:610px\"></div>");
    //三级第二压缩机组-压缩机B2出口-温度
    $(".imgbackground").append("<div  class=\"" + (data.Group4_Compressor_B_Outlet_T_high == "0" ? "imgclassyellow" : "imgclassred") + "\"  style=\"left:460px;top:682px\"></div>");
    //三级第二压缩机组-压缩机B2-压力
    $(".imgbackground").append("<div  class=\"" + (data.Group4_Compressor_B_Outlet_P_low == "0" && data.Group4_Compressor_B_Outlet_P_high == "0" ? "imgclassblue" : "imgclassred") + "\"  style=\"left:530px;top:682px\"></div>");
    //重新渲染
    $.parser.parse('.imgbackground');
}
//加载启动与关停时间
// function InitTimeData() {
//     let data = { "startDate": "2021-02-14 12:30:00", "endDate": "2021-02-14 12:30:00" }
//     $("#sp_StartDate").html("上次启动时间： " + data.startDate);
//     $("#sp_EndDate").html("上次关停时间： " + data.endDate);
// }
// 加载状态
function InitStatusData() {
    let url = path + '/ls172/data-analysis/newStatus'
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        success: function (data) {
            data1 = data.data.Group1
            data2 = data.data.Group2
            data3 = data.data.Group3
            data4 = data.data.Group4
            $("#sp_cp1_temp").html(data1[0].value.toFixed() + "°C");
            $("#sp_cp1_tempday").html(data1[1].value.toFixed() + "%");
            $("#sp_cp1_p").html(data1[2].value.toFixed() + "Mpa");
            $("#sp_cp1_pday").html(data1[3].value.toFixed() + "%");

            $("#sp_cp2_temp").html(data2[0].value.toFixed() + "°C");
            $("#sp_cp2_tempday").html(data2[1].value.toFixed() + "%");
            $("#sp_cp2_p").html(data2[2].value.toFixed() + "Mpa");
            $("#sp_cp2_pday").html(data2[3].value.toFixed() + "%");

            $("#sp_cp3_temp").html(data3[0].value.toFixed() + "°C");
            $("#sp_cp3_tempday").html(data3[1].value.toFixed() + "%");
            $("#sp_cp3_p").html(data3[2].value.toFixed() + "Mpa");
            $("#sp_cp3_pday").html(data3[3].value.toFixed() + "%");

            $("#sp_cp4_temp").html(data4[0].value.toFixed() + "°C");
            $("#sp_cp4_tempday").html(data4[1].value.toFixed() + "%");
            $("#sp_cp4_p").html(data4[2].value.toFixed() + "Mpa");
            $("#sp_cp4_pday").html(data4[3].value.toFixed() + "%");
        },
        error: function (data) {
            console.log("code", data);
        }
    });
}
// function getNowTime() {
//     let url = path + '/ls172/ls172-workorder/getLocalTime'
//     $.ajax({
//         url: url,
//         type: "GET",
//         async: false,
//         success: function (data) {
//             document.getElementById('sp_Sdate').innerText = '最新状态 (' + data.data.date + ')'
//         },
//         error: function (data) {
//             console.log("code", data);
//         }
//     })
// }
